'use strict';

const Controller = require('egg').Controller;
const util = require('../utils');

class onlineController extends Controller {
    /*线上班主页数据******************************************************************/
    async onlineIndex(){
        const { initInterestData } = require('../utils/index');
        /*分类*/
        const category = await this.ctx.service.mainCategory.mainCategory();
        const categoryResult = initInterestData(category);
        /*专辑列表*/
        const page = this.ctx.query.page || 1;
        const parentId = this.ctx.query.parentId||'';
        const categoryId = this.ctx.query.categoryId || parentId || '';
        const orderByField = this.ctx.query.orderByField || 'sort';
        const videoAblum = await this.ctx.service.online.videoAlbum(page,15,categoryId,orderByField,'');
        const videoRecom = await this.ctx.service.online.videoAlbumSimple(1,5,categoryId,orderByField,true);
        var noticeList = await this.ctx.service.bbs.bbsListSimple(1,10,3);
        var memberList = await this.ctx.service.banner.bannerList('vip_area');
        const data = {
            category:categoryResult,
            videoData:videoAblum,
            categoryId:categoryId,
            parentId:parentId,
            videoRecom:videoRecom,
            memberList:memberList,
            noticeList:noticeList,
        };
        await this.ctx.render('page/online/online.html',{data:data});
    }
    
    /*线上班内容数据******************************************************************/
    async online_content(){
        const id = this.ctx.params.id || '';
        /*视频简介*/
        const onlineAlbumDetail = await this.ctx.service.online.onlineAlbumDetail(id);
        /*目录*/
        const onlineAlbumOutline = await this.ctx.service.online.onlineAlbumOutlineRec(id);
        const categoryId = onlineAlbumDetail.onlineClass.categoryId||'';
        const videoRecom = await this.ctx.service.online.videoAlbumSimple(1,10,categoryId,'playCount',true);
        const data={
            onlineDetail:onlineAlbumDetail.onlineClass,
            videoOutline:onlineAlbumOutline,
            videoData:videoRecom,
        };
        await this.ctx.render('page/online/online_content.html',{data:data});
    }
    
}

module.exports = onlineController;

